<style lang="less" rel="stylesheet/less" type="text/less">
.v-admin-equipment-views {
  padding: 20px;
  height: 100%;
}
</style>
<template>
  <div class="v-admin-equipment-views">
    <Recharge-create ref="create" @rechargeCreate="rechargeAPI" />
  </div>
</template>
<script>
import RechargeCreate from "./create";
import qs from "qs";

export default {
  components: {
    RechargeCreate
  },
  data() {
    return {};
  },
  methods: {
    rechargeAPI(params) {
      this.axios
        .get(`${window.location.origin}/web/v1/pay/alipay`, {
          params
        })
        .then(({ data }) => {
          console.log(data);

          this.$Message.loading({
            content: "正在为你跳转支付宝进行充值",
            duration: 1
          });
          // 	const div = document.createElement('div');
          // 	div.innerHTML = data;
          // 	div.innerHTML =
          // document.body.appendChild(div);
          // 	document.forms[0].submit();

          // const divForm = document.getElementsByTagName('divform');
          // if (divForm.length) {
          // 	document.body.removeChild(divForm[0]);
          // }
          // const div = document.createElement('divform');
          // div.innerHTML = data; // data就是接口返回的form 表单字符串
          // document.body.appendChild(div);
          // document.forms[0].setAttribute('target', '_blank'); // 新开窗口跳转
          // document.forms[0].submit();

          document.querySelector("body").innerHTML = data; // 查找到当前页面的body，将后台返回的form替换掉他的内容
          document.forms[0].submit(); // 执行submit表单提交，让页面重定向，跳转到支付宝页面
          this.$refs.create.handleReset("formValidate");
        })
        .catch(err => {
          this.$Message.error(err.message);
        });
    }
  }
};
</script>
